from PyQt4.QtGui import QAction
from PyQt4.QtGui import QIcon
from PyQt4.QtCore import SIGNAL
from PyQt4.QtCore import QObject

import config

class EditMenu(object):

    def __init__(self, menu, tool, main):
        self._main = main

        undoAction = menu.addAction(QIcon(config.img['undo']), 'Undo')
        redoAction = menu.addAction(QIcon(config.img['redo']), 'Redo')
        cutAction = menu.addAction(QIcon(config.img['cut']), '&Cut (Ctrl+X)')
        copyAction = menu.addAction(QIcon(config.img['copy']), '&Copy (Ctrl+C)')
        pasteAction = menu.addAction(QIcon(config.img['paste']), '&Paste (Ctrl+V)')
        disableAction = menu.addAction('&Disable Web Preview')
        disableAction.setCheckable(True)
        prefAction = menu.addAction(QIcon(config.img['pref']), 'Preference&s')

        tool.addAction(cutAction)
        tool.addAction(copyAction)
        tool.addAction(pasteAction)
        tool.addAction(disableAction)

        QObject.connect(cutAction, SIGNAL("triggered()"), lambda: self._main.obtain_editor().cut())
        QObject.connect(copyAction, SIGNAL("triggered()"), lambda: self._main.obtain_editor().copy())
        QObject.connect(pasteAction, SIGNAL("triggered()"), lambda: self._main.obtain_editor().paste())
        QObject.connect(redoAction, SIGNAL("triggered()"), lambda: self._main.obtain_editor().redo())
        QObject.connect(undoAction, SIGNAL("triggered()"), lambda: self._main.obtain_editor().undo())
        QObject.connect(disableAction, SIGNAL("triggered()"), self._main.manage_refresh)
        #QObject.connect(pref, SIGNAL("triggered()"), self._main.manage_refresh)
